From: Tim Lunn Date: Sun, 6 Oct 2013 08:21:50 +0000 (+1100) Subject: port shell-js to c++ X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~3151 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=e9fbbf40009cf3733ff5bbecdf2369bad8f1acb3;p=gnome-shell.git port shell-js to c++ https://bugzilla.gnome.org/show_bug.cgi?id=711052 --- diff --git a/configure.ac b/configure.ac index d149ff2b1..da937cd09 100644 --- a/configure.ac +++ b/configure.ac @@ -16,6 +16,7 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) # Checks for programs. AC_PROG_CC +AC_PROG_CXX # Initialize libtool LT_PREREQ([2.2.6]) diff --git a/src/Makefile.am b/src/Makefile.am index 8041052d7..a9f4c6271 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -207,7 +207,7 @@ endif HAVE_MUTTER_WAYLAND libgnome_shell_js_la_SOURCES = \ shell-js.h \ - shell-js.c \ + shell-js.cpp \ $(NULL) libgnome_shell_js_la_LIBADD = \ diff --git a/src/shell-js.c b/src/shell-js.c deleted file mode 100644 index 149dcd041..000000000 --- a/src/shell-js.c +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -#include "config.h" - -#include "shell-js.h" - -#include -#include -#include -#include - -/** - * shell_js_add_extension_importer: - * @target_object_script: JavaScript code evaluating to a target object - * @target_property: Name of property to use for importer - * @directory: Source directory: - * @error: A #GError - * - * This function sets a property named @target_property on the object - * resulting from the evaluation of @target_object_script code, which - * acts as a GJS importer for directory @directory. - * - * Returns: %TRUE on success - */ -gboolean -shell_js_add_extension_importer (const char *target_object_script, - const char *target_property, - const char *directory, - GError **error) -{ - jsval target_object; - GList *contexts; - JSContext *context; - char *search_path[2] = { 0, 0 }; - gboolean ret = FALSE; - - /* Take the first GjsContext from all of them -- - * we should only ever have one context, so this - * should be alright. */ - contexts = gjs_context_get_all (); - context = gjs_context_get_native_context (contexts->data); - g_list_free_full (contexts, g_object_unref); - - JS_BeginRequest (context); - - /* This is a bit of a hack; ideally we'd be able to pass our target - * object directly into this function, but introspection doesn't - * support that at the moment. Instead evaluate a string to get it. */ - if (!JS_EvaluateScript(context, - JS_GetGlobalObject(context), - target_object_script, - strlen (target_object_script), - "", - 0, - &target_object)) - { - gjs_log_exception(context); - g_set_error(error, - G_IO_ERROR, - G_IO_ERROR_FAILED, - "Unable to import %s", target_object_script); - goto out; - } - - if (!JSVAL_IS_OBJECT (target_object)) - { - g_error ("shell_js_add_extension_importer: invalid target object"); - goto out; - } - - search_path[0] = (char*)directory; - gjs_define_importer (context, JSVAL_TO_OBJECT (target_object), target_property, (const char **)search_path, FALSE); - ret = TRUE; - - out: - JS_EndRequest (context); - return ret; -} diff --git a/src/shell-js.cpp b/src/shell-js.cpp new file mode 100644 index 000000000..7d057c9e9 --- /dev/null +++ b/src/shell-js.cpp @@ -0,0 +1,78 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +#include "config.h" + +#include "shell-js.h" + +#include +#include +#include +#include + +/** + * shell_js_add_extension_importer: + * @target_object_script: JavaScript code evaluating to a target object + * @target_property: Name of property to use for importer + * @directory: Source directory: + * @error: A #GError + * + * This function sets a property named @target_property on the object + * resulting from the evaluation of @target_object_script code, which + * acts as a GJS importer for directory @directory. + * + * Returns: %TRUE on success + */ +gboolean +shell_js_add_extension_importer (const char *target_object_script, + const char *target_property, + const char *directory, + GError **error) +{ + jsval target_object; + GList *contexts; + JSContext *context; + char *search_path[2] = { 0, 0 }; + gboolean ret = FALSE; + + /* Take the first GjsContext from all of them -- + * we should only ever have one context, so this + * should be alright. */ + contexts = gjs_context_get_all (); + context = (JSContext*) gjs_context_get_native_context ((GjsContext*)contexts->data); + g_list_free_full (contexts, g_object_unref); + + JS_BeginRequest (context); + + /* This is a bit of a hack; ideally we'd be able to pass our target + * object directly into this function, but introspection doesn't + * support that at the moment. Instead evaluate a string to get it. */ + if (!JS_EvaluateScript(context, + JS_GetGlobalObject(context), + target_object_script, + strlen (target_object_script), + "", + 0, + &target_object)) + { + gjs_log_exception(context); + g_set_error(error, + G_IO_ERROR, + G_IO_ERROR_FAILED, + "Unable to import %s", target_object_script); + goto out; + } + + if (!JSVAL_IS_OBJECT (target_object)) + { + g_error ("shell_js_add_extension_importer: invalid target object"); + goto out; + } + + search_path[0] = (char*)directory; + gjs_define_importer (context, JSVAL_TO_OBJECT (target_object), target_property, (const char **)search_path, FALSE); + ret = TRUE; + + out: + JS_EndRequest (context); + return ret; +}